﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Activation;
using System.ServiceModel.Description;

namespace Justin.Wcf.Services
{
    public class CalculatorService : ICalculator
    {
        public double Add(double x, double y)
        {
            return x + y;
        }

        public double Subtract(double x, double y)
        {
            return x - y;
        }

        public double Multiply(double x, double y)
        {
            return x * y;
        }

        public double Divide(double x, double y)
        {
            return x / y;
        }
    }

    public class PrinterService : IPrinter
    {
        public String TurnOn()
        {
            return "Printer turn on";
        }

        public String TurnOff()
        {
            return "Printer turn off";
        }

        public string Print(string content)
        {

            return "Print completed";
        }

        public string Scan(string content)
        {
            return "Scan completed";
        }
    }

    public class HostFactory : ServiceHostFactory
    {
        protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        {
            ServiceHost host = new ServiceHost(serviceType, baseAddresses);

            host.AddServiceEndpoint(typeof(Justin.Wcf.Services.ICalculator), new NetTcpBinding(), "net.tcp://www.wcf.com/");
            host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "MEX");

            return host;
        }
    }
}
